<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/5
 * Time: 15:41
 */

namespace app\api\controller;


use think\Db;

/**
 * @package app\api\controller
 * 时时彩玩法
 * 双面玩法：
 * 【
 *      '双面盘'=>[
 *          '总和值'=>86-80,
 *          '后二和值'=>无,
 *          '万位'=>87-81,
 *          '千位'=>88-81,
 *          '百位'=>89-81,
 *          '十位'=>90-81,
 *          '个位'=>91-81
 *       ]，
 *      '数字盘'=>49-51,
 *      '龙虎斗'=>[     龙=>78,   虎=>79,    和=>975
 *          '万千'=>76,
 *          '万百'=>77,
 *          '万十'=>78,
 *          '万个'=>79,
 *          '千百'=>80,
 *          '千十'=>81,
 *          '千个'=>82,
 *          '百十'=>83,
 *          '百个'=>84,
 *          '十个'=>85
 *      ],
 *      '后三组六' => 26
 * 】
 *  官方玩法
 *【 参考赢彩，玩法ID为路由中的参数xflid，例如：https://6709a.com/mobile/game/index.html?game_id=1&dflid=6&xflid=50】
 *
 * 投注号码格式：
 * 五星直选复式-1：1 , 2 6 , 3 , 4 6 , 3
 * 五星直选组合-2：2 8 , 2 , 2 8 , 2 , 2
 * 五星组选120-3：1 2 3 4 6 8 9
 * 五星组选60-4：1 3 9 , 0 2 3 4 7
 * 五星组选30-5：0 1 2 , 2 4 9
 * 五星组选20-6：1 3 5 7 9 , 0 1 2 3 4 5 6 7 8 9
 * 五星组选10-7：1 3 5 7 9 , 0 1 2 3 4 5 6 7 8 9
 * 五星组选5-8：1 3 5 7 9 , 0 1 2 3 4 5 6 7 8 9
 *
 * 四星后四直选复式-9：0 , 0 1 , 0 1 , 0 1
 * 四星后四直选组合-10：0 1 2 3 4 , 1 3 5 7 9 , 5 6 7 8 9 , 0 2 4 6 8
 * 四星后四组选24-11：0 1 2 5 6 8
 * 四星后四组选12-12：0 1 2 3 4 , 1 3 5 7 9
 * 四星后四组选6-13：0 2 7 8
 * 四星后四组选4-14：0 1 2 3 4 , 0 1 2 3 4 5 6 7 8 9
 * 四星前四直选复式-15：1 2 , 3 4 , 5 6 , 7 8
 * 四星前四直选组合-16：1 2 , 3 4 , 5 6 , 7 8
 * 四星前四组选24-17：0 1 2 5 6 8
 * 四星前四组选12-18：0 1 2 3 4 , 1 3 5 7 9
 * 四星前四组选6-19：0 2 7 8
 * 四星前四组选4-20：0 1 2 3 4 , 0 1 2 3 4 5 6 7 8 9
 *
 * 后三直选复式-21：0 , 1 , 0 4 9
 * 后三直选和值-22：1 7 13 19
 * 后三直选跨度-23：
 * 后三直选和值尾数-24：
 * 后三组选组三-25：
 * 后三组选组六-26：
 * 中三直选复式-27：
 * 中三直选和值-28：
 * 中三直选跨度-29：
 * 中三直选和值尾数-30：
 * 中三组选组三-31：
 * 中三组选组六-32：
 * 前三直选复式-33：
 * 前三直选和值-34：
 * 前三直选跨度-35：
 * 前三直选和值尾数-36：
 * 前三组选组三-37：
 * 前三组选组六-38：
 */
header("ACCESS-CONTROL-ALLOW-ORIGIN:http://114.215.68.205");

class PlaySsc extends Base{

    public function index(){

        $czid = input("czid",0);
        $ret = array(
            'result'=>0,
            'ResultMsg' => ''
        );
        if( empty($czid) ){
            $ret['ResultMsg'] = '请求参数错误';
            return json_encode($ret,JSON_UNESCAPED_UNICODE);
        }
        $this->qihaoNext($czid);
        $now = time();
        $next = $this->nextResult($czid);
        $datas = [];
        $datas['current']['next_no'] = $next['num'];
        $datas['current']['next_time'] = $next['time'];

//        $fp_time = Db::name('caipai_list')->where(['id'=>$czid])->value('cp_fp_time');
//        if(!empty($datas['current']['next_time'])) $datas['current']['next_time'] = intval($datas['current']['next_time'])-intval($fp_time);

        $current = $this->currentHasResult($czid,$now);
        $datas['current']['current_no'] = $current['num'];
        $datas['current']['current_time'] = $current['time'];
        $current_kjjg = str_split($current['kjjg']);
        $datas['current']['current_kjjg'] = $current_kjjg;
        $datas['current']['_1'] = $datas['current']['_2'] = $datas['current']['_3'] = $datas['current']['_4'] = $datas['current']['_5'] = '';
        for($i=0;$i<5;$i++){
            $j = $i+1;
            intval($current_kjjg[$i]) > 4  ? $datas['current']['_'.$j].='大' : $datas['current']['_'.$j].='小';
            0 == $current_kjjg[$i] % 2 ? $datas['current']['_'.$j].='双' : $datas['current']['_'.$j].='单';
        }
        $datas['current']['_6'] = $this->afterThree($current_kjjg);
        $datas['current']['_7'] = array_sum(array_slice($current_kjjg,0,3));

        $before = $this->currentResult($czid,$now);
        $datas['current']['before_no'] = $before['num'];
        $datas['current']['amount'] = Db::name("time")->where(['czid'=>$czid,'jztime'=>['>=',date('H:i:s',time())]])->count();

        $list = Db::name('kjjg_list')->where('czid',$czid)->where('kjjg','<>','0')->field("qihao,kjjg,jztime")->order('jztime','DESC')->paginate(10)->each(function($v){

            $v['kjjg'] = str_split($v['kjjg']);
            $v['_1'] = $v['_2'] = $v['_3'] = $v['_4'] = $v['_5'] = '';
            for($i=0;$i<5;$i++){
                $j = $i+1;
                intval($v['kjjg'][$i]) > 4  ? $v['_'.$j].='大' : $v['_'.$j].='小';
                0 == $v['kjjg'][$i] % 2 ? $v['_'.$j].='双' : $v['_'.$j].='单';
            }
            $v['_6'] = $this->afterThree($v['kjjg']);
            unset($v['jztime']);
            return $v;
        })->toArray();
        $list && $list = $list['data'];
        $datas['history'] = $list;
        $ret['result'] = 1;
        $ret['datas'] = $datas;
        return json_encode($ret,JSON_UNESCAPED_UNICODE);
    }
    public function currentPeriod(){

        $czid = input("czid",0);
        $ret = array(
            'result'=>0,
            'ResultMsg' => ''
        );
        if( empty($czid) ){
            $ret['ResultMsg'] = '请求参数错误';
            return json_encode($ret,JSON_UNESCAPED_UNICODE);
        }
        $this->qihaoNext($czid);
        $before_redis = $this->currentResult($czid,time());
        $datas = [
            'kjjg' => [],
            'qihao' => '',
            'jztime' => '',
            '_1' => '',
            '_2' => '',
            '_3' => '',
            '_4' => '',
            '_5' => '',
            '_6' => '',
            '_7' => '',

        ];
        if( !empty($before_redis['kjjg']) ){

            $datas['kjjg'] = str_split($before_redis['kjjg']);
            $datas['qihao'] = $before_redis['num'];
            $datas['jztime'] = $before_redis['time'];
            for($i=0;$i<5;$i++){
                $j = $i+1;
                intval($datas['kjjg'][$i]) > 4  ? $datas['_'.$j].='大' : $datas['_'.$j].='小';
                0 == $datas['kjjg'][$i] % 2 ? $datas['_'.$j].='双' : $datas['_'.$j].='单';
            }
            $datas['_6'] = $this->afterThree($datas['kjjg']);
            $datas['_7'] = array_sum(array_slice($datas['kjjg'],0,3));
        }
        $ret['result'] = 1;
        $ret['datas'] = $datas;
        return json_encode($ret,JSON_UNESCAPED_UNICODE);
    }
    public function odds(){
        $id = input("id",0);
        $czid = input('czid',0);
        $ret = array(
            'result'=>0,
            'ResultMsg' => ''
        );
        if( empty($id) ){
            $ret['ResultMsg'] = '传入信息错误';
            return json_encode($ret,JSON_UNESCAPED_UNICODE);
        }
        $idAttr = explode(',',trim($id));
        if( 1==count($idAttr) ){
            $where = ['id'=>$id,'open'=>1];
            $where1 = ['play_id'=>$id,'open'=>1,'czid'=>$czid];
        }else{
            $where = ['id'=>['in',$idAttr],'open'=>1];
            $where1 = ['play_id'=>['in',$idAttr],'open'=>1,'czid'=>$czid];
        }
        if( !empty($czid) ){
            $classify = Db::name('play_classify_ext')->where($where1)->value("GROUP_CONCAT(peilv_ids) as ids");
            if( empty($classify) ){
                $classify = Db::name('play_classify')->where($where)->value("GROUP_CONCAT(peilv_ids) as ids");
            }
        }else{
            $classify = Db::name('play_classify')->where($where)->value("GROUP_CONCAT(peilv_ids) as ids");
        }
        $peilv = Db::name("peilv")->where("id in ($classify)")->column("id,zgpl,peilv_name");
        $peilv = array_values($peilv);
        if( 105==intval($id) ) {
            $end_pl = array_slice($peilv,-4,4);
            array_splice($peilv,0,0,$end_pl);
            array_splice($peilv,-4);
        }elseif(in_array(intval($id),[239,242,240,222,223,224,225])){
            $list = config('hk6.ZODIAC');
            foreach($list as $k=>$v){
                $ret['animals'][$v][] = strval($k);
            }
        }elseif(in_array(intval($id),[255,226,227,228,229])){
            $ret['tail'] = [
                '0尾' => ['10','20','30','40'],
                '1尾' => ['01','11','21','31','41'],
                '2尾' => ['02','12','22','32','42'],
                '3尾' => ['03','13','23','33','43'],
                '4尾' => ['04','14','24','34','44'],
                '5尾' => ['05','15','25','35','45'],
                '6尾' => ['06','16','26','36','46'],
                '7尾' => ['07','17','27','37','47'],
                '8尾' => ['08','18','28','38','48'],
                '9尾' => ['08','19','29','39','49'],
            ];
        }
        $ret['result'] = 1;
        $ret['datas'] = $peilv;
        return json_encode($ret,JSON_UNESCAPED_UNICODE);
    }
}